package com.example.springbootblog.controller;

import com.example.springbootblog.common.pojo.request.RegisterInfoParam;
import com.example.springbootblog.common.pojo.request.UserLoginParam;
import com.example.springbootblog.common.pojo.response.UserInfoResponse;
import com.example.springbootblog.common.pojo.response.UserLoginResponse;
import com.example.springbootblog.service.UserService;
import jakarta.annotation.Resource;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户密码校验以及用户信息控制层
 */
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userServiceImpl")
    UserService userService;



//    获取登录页面
    @RequestMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginParam param) {
        return userService.login(param);
    }

    @RequestMapping("/getUserInfo")
    //查询用户信息
    public UserInfoResponse getUserInfo(@NonNull Integer userId) {
//        修改一下映射的用户名
        UserInfoResponse userInfoById = userService.getUserInfoById(userId);
        return userInfoById;
    }


    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NonNull Integer blogId) {
//        修改一下映射的用户名
        UserInfoResponse authorInfoById = userService.getAuthorInfoById(blogId);
        return authorInfoById;
    }


    @RequestMapping("/register")
    public boolean register(@RequestBody  @Validated RegisterInfoParam userData) {
        log.info("前端传入的参数为: {}", userData );
        return userService.registerUser(userData);
    }


}
